package com.egao.common.module.recommendation.controller;

import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.recommendation.entity.FreelanceRegistrationForm;
import com.egao.common.module.recommendation.entity.vo.RecommendationAuditParam;
import com.egao.common.module.recommendation.entity.vo.RecommendationListVo;
import com.egao.common.module.recommendation.service.IFreelanceRegistrationFormService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *  控制器
 *
 * @author cj
 */
@Api(tags = "管理")
@RestController
@RequestMapping("${api}")
public class FreelanceRegistrationFormController extends BaseController {

    private IFreelanceRegistrationFormService freelanceRegistrationFormService;

    @Autowired
    public FreelanceRegistrationFormController(IFreelanceRegistrationFormService freelanceRegistrationFormService){
        this.freelanceRegistrationFormService = freelanceRegistrationFormService;
    }

    @PreAuthorize("hasAuthority('freeForm:list')")
    @ApiOperation("查询列表")
    @GetMapping("/freeRegisForm/list")
    public PageResult<RecommendationListVo> list(HttpServletRequest request) {
        PageParam<FreelanceRegistrationForm> pageParam = new PageParam<>(request);
        return freelanceRegistrationFormService.list(pageParam);
    }

    @PreAuthorize("hasAuthority('freeForm:read')")
    @ApiOperation("查询单个")
    @GetMapping("/freeRegisForm/get/{id}")
    public JsonResult read(@PathVariable("id") Integer id) {
        return freelanceRegistrationFormService.read(id);
    }

    @PreAuthorize("hasAuthority('freeForm:my')")
    @ApiOperation("查询单个")
    @GetMapping("/freeRegisForm/my")
    public JsonResult read() {return freelanceRegistrationFormService.read();}

    @PreAuthorize("hasAuthority('freeForm:add')")
    @ApiOperation("添加")
    @PostMapping("/freeRegisForm/add")
    public JsonResult add(@RequestBody FreelanceRegistrationForm model) {
        return freelanceRegistrationFormService.add(model);
    }

//   暂存
    @PreAuthorize("hasAuthority('freeForm:update')")
    @ApiOperation("暂存")
    @PostMapping("/freeRegisForm/update")
    public JsonResult update(@RequestBody FreelanceRegistrationForm model) {
        return freelanceRegistrationFormService.update(model);
    }

//   提交
    @PreAuthorize("hasAuthority('freeForm:submit')")
    @ApiOperation("提交")
    @PostMapping("/freeRegisForm/submit/{id}")
    public JsonResult submit(@PathVariable("id") Integer id) {
        return freelanceRegistrationFormService.submit(id);
    }

    @PreAuthorize("hasAuthority('freeForm:delete')")
    @ApiOperation("删除")
    @GetMapping("/freeRegisForm/delete/{ids}")
    public JsonResult delete(@PathVariable("ids") Integer[] ids) {
        return freelanceRegistrationFormService.delete(ids);
    }

//    审核
    @PreAuthorize("hasAuthority('freeForm:audit')")
    @ApiOperation("审核")
    @PostMapping("/freeRegisForm/audit")
    public JsonResult audit(@RequestBody RecommendationAuditParam param) {
        return freelanceRegistrationFormService.audit(param);
    }

//  导出
    @PreAuthorize("hasAuthority('freeForm:export')")
    @ApiOperation("导出")
    @GetMapping("/freeRegisForm/export/{id}")
    public JsonResult export(@PathVariable("id") Integer id, HttpServletResponse response) throws IOException {
        return freelanceRegistrationFormService.export(id,response);
    }

}